package edu.byu.intex2.tester;

/////////////////////////////////////////////////////////////////
///   This file is an example solution for TwoTicketsPlus in
///   the ISys Core at Brigham Young University.  Students
///   may use the code as part of the 413 course in their
///   milestones following this one, but no permission is given
///   to use this code is any other way.  Since we will likely
///   use this case again in a future year, please DO NOT post
///   the code to a web site, share it with others, or pass
///   it on in any way.

/*
 * Note that I've placed this file *outside* the edu.byu.isys413.cca.data
 * package because it mimicks the GUI (which is also outside the data layer).
 * This prevents the Tester from ever calling package-protected methods.
 * 
 */




import java.sql.*;
import java.util.*;
import java.text.SimpleDateFormat;



/////////////////////////////////////////////////
///   This class contains the actual testing
///   methods.  You can split it into many
///   classes, but I just put everything in one
///   class for simplicity.

/** The container of all the tests */
public class TestDataLayerTests extends TestCase {
  /** Constructor */
  public TestDataLayerTests() {
  }//constructor
  
  /** Tests the customer BO and DAO (this really should be split into many methods) */
  public void testCustomer() throws Exception {
    String guid = GUID.generate();
    Customer cust = CustomerDAO.getInstance().create(guid);
    cust.setCustomerNumber("A1354");
    cust.setName("Jack O'Niell");
    cust.setAddress("Cheyenne Mountain, CO");
    cust.setPhone("801-422-BYU1");
    cust.save(); // will save with insert statement
    
    cust.setAddress("Glacier National Park, MO");
    cust.save(); // this will save with the update statement
    
    // this one will come from the cache -- should be the exact same object
    Customer cust2 = CustomerDAO.getInstance().read(guid);
    assertSame(cust, cust2);
    
    // this one will come all the way from the DB -- should be a new object
    Cache.getInstance().clear();
    Customer cust3 = CustomerDAO.getInstance().read(guid);
    assertNotSame(cust, cust3);
    assertEquals(cust.getName(), cust3.getName());
    assertNotNull(cust.getName());
    assertEquals(cust.getCustomerNumber(), cust3.getCustomerNumber());
    assertNotNull(cust.getCustomerNumber());
    assertEquals(cust.getAddress(), cust3.getAddress());
    assertNotNull(cust.getAddress());
    assertEquals(cust.getPhone(), cust3.getPhone());
    assertNotNull(cust.getPhone());

    // test the search methods in the DAO
    List<Customer> allCust;
    allCust = CustomerDAO.getInstance().getAll();
    assertEquals(allCust.size(), 3); // 2 are in the SQL create script, 1 above
    allCust = CustomerDAO.getInstance().getByPhone("801-422-BYU1");
    assertEquals(allCust.get(0).getId(), guid);
  }//testCustomer
  
  /** Tests the ticketseller BO and DAO */
  public void testTicketSeller() throws Exception {
    String guid = GUID.generate();
    TicketSeller ts = TicketSellerDAO.getInstance().create(guid);
    ts.setName("BYU Football");
    ts.setAddress("BYU Address");
    ts.setPhone("801-422-BYU1");
    ts.save(); // will save with insert statement
    
    ts.setAddress("15 Northwood Way");
    ts.save(); // this will save with the update statement
    
    // this one will come from the cache -- should be the exact same object
    TicketSeller ts2 = TicketSellerDAO.getInstance().read(guid);
    assertSame(ts, ts2);
    
    // this one will come all the way from the DB -- should be a new object
    Cache.getInstance().clear();
    TicketSeller ts3 = TicketSellerDAO.getInstance().read(guid);
    assertNotSame(ts, ts3);
    assertEquals(ts.getName(), ts3.getName());
    assertNotNull(ts.getName());
    assertEquals(ts.getAddress(), ts3.getAddress());
    assertNotNull(ts.getAddress());
    assertEquals(ts.getPhone(), ts3.getPhone());
    assertNotNull(ts.getPhone());
    
    // test the search methods in the DAO
    Cache.getInstance().clear();
    List<TicketSeller> allTicketSellers;
    allTicketSellers = TicketSellerDAO.getInstance().getAll();
    
    // now get a venue object out -- it should be a Venue, not a TicketSeller from the cache
    Venue venue = VenueDAO.getInstance().read("ts02");
    assertTrue(allTicketSellers.contains(venue));
  }//testTicketSeller

  
  /** Tests the venue BO and DAO */
  public void testVenue() throws Exception {
    String guid = GUID.generate();
    Venue venue = VenueDAO.getInstance().create(guid);
    venue.setName("Marriott Center");
    venue.setOwner("Ralph Pearson");
    venue.setAddress("BYU Address");
    venue.setPhone("801-422-BYU1");
    venue.save(); // will save with insert statement
    
    venue.setOwner("Ted Marcher");
    venue.save(); // this will save with the update statement
    
    // this one will come from the cache -- should be the exact same object
    Venue venue2 = VenueDAO.getInstance().read(guid);
    assertSame(venue, venue2);
    
    // this one will come all the way from the DB -- should be a new object
    Cache.getInstance().clear();
    Venue venue3 = VenueDAO.getInstance().read(guid);
    assertNotSame(venue, venue3);
    assertEquals(venue.getName(), venue3.getName());
    assertNotNull(venue.getName());
    assertEquals(venue.getAddress(), venue3.getAddress());
    assertNotNull(venue.getAddress());
    assertEquals(venue.getOwner(), venue3.getOwner());
    assertNotNull(venue.getOwner());
    assertEquals(venue.getPhone(), venue3.getPhone());
    assertNotNull(venue.getPhone());
    
    // test the search methods in the DAO
    List<Venue> allVenues;
    allVenues = VenueDAO.getInstance().getAll();
    assertEquals(allVenues.size(), 3);
  }//testVenue
  
  
  /** Tests the dayofweek BO and DAO */
  public void testDayOfWeek() throws Exception {
    String guid = GUID.generate();
    DayOfWeek dayofweek = DayOfWeekDAO.getInstance().create(guid);
    dayofweek.setName("Homerday");
    dayofweek.save(); // will save with insert statement
    
    dayofweek.setName("Bartday");
    dayofweek.save(); // this will save with the update statement
    
    // this one will come from the cache -- should be the exact same object
    DayOfWeek dayofweek2 = DayOfWeekDAO.getInstance().read(guid);
    assertSame(dayofweek, dayofweek2);
    
    // this one will come all the way from the DB -- should be a new object
    Cache.getInstance().clear();
    DayOfWeek dayofweek3 = DayOfWeekDAO.getInstance().read(guid);
    assertNotSame(dayofweek, dayofweek3);
    assertEquals(dayofweek.getName(), dayofweek3.getName());
    assertNotNull(dayofweek.getName());
    
    // test the search methods in the DAO
    List<DayOfWeek> allDOW;
    allDOW = DayOfWeekDAO.getInstance().getAll();
    assertEquals(allDOW.size(), 8); 
  }//testDayOfWeek  

  
  /** Tests the timeperiod BO and DAO */
  public void testTimePeriod() throws Exception {
    String guid = GUID.generate();
    TimePeriod timeperiod = TimePeriodDAO.getInstance().create(guid);
    timeperiod.setDescription("Morning");
    timeperiod.save(); // will save with insert statement
    
    timeperiod.setDescription("Midnight");
    timeperiod.save(); // this will save with the update statement
    
    // this one will come from the cache -- should be the exact same object
    TimePeriod timeperiod2 = TimePeriodDAO.getInstance().read(guid);
    assertSame(timeperiod, timeperiod2);
    
    // this one will come all the way from the DB -- should be a new object
    Cache.getInstance().clear();
    TimePeriod timeperiod3 = TimePeriodDAO.getInstance().read(guid);
    assertNotSame(timeperiod, timeperiod3);
    assertEquals(timeperiod.getDescription(), timeperiod3.getDescription());
    assertNotNull(timeperiod.getDescription());
    
    // test the search methods in the DAO
    List<TimePeriod> all;
    all = TimePeriodDAO.getInstance().getAll();
    assertEquals(all.size(), 4); 
  }//testTimePeriod  
  
  
    
  /** Tests the prodcat BO and DAO */
  public void testVenueProductionCategory() throws Exception {
    String guid = GUID.generate();
    Venue venue = VenueDAO.getInstance().read("ts02");
    VenueProductionCategory prodcat = VenueProductionCategoryDAO.getInstance().create(guid);
    prodcat.setDescription("Classical Concert");
    prodcat.setVenue(venue);
    prodcat.save(); // will save with insert statement
    
    prodcat.setDescription("Wii Tournament");
    prodcat.save(); // this will save with the update statement
    
    // this one will come from the cache -- should be the exact same object
    VenueProductionCategory prodcat2 = VenueProductionCategoryDAO.getInstance().read(guid);
    assertSame(prodcat, prodcat2);
    
    // this one will come all the way from the DB -- should be a new object
    Cache.getInstance().clear();
    VenueProductionCategory prodcat3 = VenueProductionCategoryDAO.getInstance().read(guid);
    assertNotSame(prodcat, prodcat3);
    assertEquals(prodcat.getDescription(), prodcat3.getDescription());
    assertNotNull(prodcat.getDescription());
    assertNotNull(prodcat.getVenue());
    assertEquals(prodcat.getVenue().getId(), venue.getId());
    
    // test the search methods in the DAO
    List<VenueProductionCategory> all;
    all = VenueProductionCategoryDAO.getInstance().getAll();
    assertEquals(all.size(), 6); 
  }//testProductionCategory  
  
  
    
  /** Tests the section BO and DAO */
  public void testSection() throws Exception {
    String guid = GUID.generate();
    Section section = SectionDAO.getInstance().create(guid);
    section.setSectionNumber("New1");
    section.save(); // will save with insert statement
    
    section.setSectionNumber("New1A");
    section.save(); // this will save with the update statement
    
    // this one will come from the cache -- should be the exact same object
    Section section2 = SectionDAO.getInstance().read(guid);
    assertSame(section, section2);
    
    // this one will come all the way from the DB -- should be a new object
    Cache.getInstance().clear();
    Section section3 = SectionDAO.getInstance().read(guid);
    assertNotSame(section, section3);
    assertEquals(section.getSectionNumber(), section3.getSectionNumber());
    assertNotNull(section.getSectionNumber());
    
    // test the search methods in the DAO
    List<Section> all;
    all = SectionDAO.getInstance().getAll();
    assertEquals(all.size(), 10); 
  }//testSection    
  
  
  
  /** Tests the venconf BO and DAO */
  public void testVenueConfiguration() throws Exception {
    String guid = GUID.generate();
    Venue venue = VenueDAO.getInstance().read("ts02");
    VenueConfiguration venconf = VenueConfigurationDAO.getInstance().create(guid);
    venconf.setName("Vertical Configuration");
    venconf.setDescription("Description for new venconf");
    venconf.setTotalSeats(500);
    venue.addVenueConfiguration(venconf);
    venconf.save(); // will save with insert statement
    venue.save();
    
    venconf.setDescription("New description");
    venconf.save(); // this will save with the update statement
    
    // this one will come from the cache -- should be the exact same object
    VenueConfiguration venconf2 = VenueConfigurationDAO.getInstance().read(guid);
    assertSame(venconf, venconf2);
    
    // this one will come all the way from the DB -- should be a new object
    Cache.getInstance().clear();
    VenueConfiguration venconf3 = VenueConfigurationDAO.getInstance().read(guid);
    assertNotSame(venconf, venconf3);
    assertEquals(venconf.getName(), venconf3.getName());
    assertNotNull(venconf.getName());
    assertEquals(venconf.getDescription(), venconf3.getDescription());
    assertNotNull(venconf.getDescription());
    assertEquals(venconf.getTotalSeats(), venconf3.getTotalSeats());
    
    // test the search methods in the DAO
    List<VenueConfiguration> all;
    all = VenueConfigurationDAO.getInstance().getAll();
    assertEquals(all.size(), 6); 
  }//testVenueConfiguration    
  
  
  /** Tests the production BO and DAO */
  public void testProduction() throws Exception {
    VenueConfiguration venueconfig = VenueConfigurationDAO.getInstance().read("vc20");
    ConceptualPackage pkg = ConceptualPackageDAO.getInstance().read("cp86");
    VenueProductionCategory prodcat = VenueProductionCategoryDAO.getInstance().read("8623n");
    String guid = GUID.generate();
    Production production = ProductionDAO.getInstance().create(guid);
    production.setName("Vertical Configuration");
    production.setDescription("Description for new production");
    production.setStartDate(new java.util.Date());
    production.setEndDate(new java.util.Date());
    production.setCommission(10.00);
    production.setProductionCategory(prodcat);
    venueconfig.addProduction(production);
    production.save(); // will save with insert statement
    venueconfig.save();
    
    production.setName("Vertical 2");
    production.save(); // this will save with the update statement
    
    // this one will come from the cache -- should be the exact same object
    Production production2 = ProductionDAO.getInstance().read(guid);
    assertSame(production, production2);
    
    // this one will come all the way from the DB -- should be a new object
    SimpleDateFormat fmt = new SimpleDateFormat("yyyy-MM-dd");
    Cache.getInstance().clear();
    Production production3 = ProductionDAO.getInstance().read(guid);
    assertNotSame(production, production3);
    assertEquals(production.getName(), production3.getName());
    assertNotNull(production.getName());
    assertEquals(production.getDescription(), production3.getDescription());
    assertNotNull(production.getDescription());
    assertEquals(fmt.format(production.getStartDate()), fmt.format(production3.getStartDate()));
    assertNotNull(production.getStartDate());
    assertEquals(fmt.format(production.getEndDate()), fmt.format(production3.getEndDate()));
    assertNotNull(production.getEndDate());
    assertEquals(production.getCommission(), production3.getCommission());
    assertNotNull(production.getProductionCategory());
    assertEquals(production3.getProductionCategory().getId(), prodcat.getId());
    assertNotNull(production3.getVenueConfiguration());
    assertEquals(production3.getVenueConfiguration().getId(), venueconfig.getId());
    
    // test the search methods in the DAO
    List<Production> all;
    all = ProductionDAO.getInstance().getAll();
    assertEquals(all.size(), 5); 
  }//testProduction    
  
  
  /** Tests the Conceptual ConceptualPackage BO and DAO */
  public void testConceptualPackage() throws Exception {
    String guid = GUID.generate();
    ConceptualPackage pkg = ConceptualPackageDAO.getInstance().create(guid);
    pkg.setDiscount(105.00);
    pkg.setName("Musical Package");
    pkg.setDescription("Package of musical events");
    pkg.save(); // will save with insert statement
    
    pkg.setName("Musical 2 Package");
    pkg.save(); // this will save with the update statement
    
    // this one will come from the cache -- should be the exact same object
    ConceptualPackage pkg2 = ConceptualPackageDAO.getInstance().read(guid);
    assertSame(pkg, pkg2);
    
    // this one will come all the way from the DB -- should be a new object
    SimpleDateFormat fmt = new SimpleDateFormat("yyyy-MM-dd");
    Cache.getInstance().clear();
    ConceptualPackage pkg3 = ConceptualPackageDAO.getInstance().read(guid);
    assertNotSame(pkg, pkg3);
    assertEquals(pkg.getDiscount(), pkg3.getDiscount());
    assertEquals(pkg.getName(), pkg3.getName());
    assertNotNull(pkg.getName());
    assertEquals(pkg.getDescription(), pkg3.getDescription());
    assertNotNull(pkg.getDescription());
    
    // test the search methods in the DAO
    List<ConceptualPackage> all;
    all = ConceptualPackageDAO.getInstance().getAll();
    assertEquals(all.size(), 3); 
  }//testPackage    
  
  
  /** Tests the Event BO and DAO */
  public void testEvent() throws Exception {
    Production prod = ProductionDAO.getInstance().read("p888");
    TimePeriod timeperiod = TimePeriodDAO.getInstance().read("tp1");
    DayOfWeek dow = DayOfWeekDAO.getInstance().read("d5");
    
    String guid = GUID.generate();
    Event event = EventDAO.getInstance().create(guid);
    event.setEventNumber("IntexSaturday1");
    event.setDayOfWeek(dow);
    event.setStatus("seats available");
    event.setStartDate(new java.util.Date());
    event.setProduction(prod);
    event.setTimePeriod(timeperiod);
    event.save(); // will save with insert statement
    
    // this one will come from the cache -- should be the exact same object
    Event event2 = EventDAO.getInstance().read(guid);
    assertSame(event, event2);
    
    // this one will come all the way from the DB -- should be a new object
    Cache.getInstance().clear();
    Event event3 = EventDAO.getInstance().read(guid);
    assertNotSame(event, event3);
    assertNotNull(event.getEventNumber());
    assertEquals(event.getEventNumber(), event3.getEventNumber());
    assertNotNull(event.getStatus());
    assertEquals(event.getStatus(), event3.getStatus());
    assertNotNull(event.getStartDate());
    assertEquals(event.getStartDate(), event3.getStartDate());
    assertNotNull(event3.getProduction());
    assertEquals(event.getProduction().getId(), event3.getProduction().getId());
    assertNotNull(event3.getTimePeriod());
    assertEquals(event.getTimePeriod().getId(), event3.getTimePeriod().getId());
    assertNotNull(event3.getDayOfWeek());
    assertEquals(event.getDayOfWeek().getId(), event3.getDayOfWeek().getId());
    
    // test the search methods in the DAO
    List<Event> all;
    all = EventDAO.getInstance().getAll();
    assertEquals(all.size(), 11); 
  }//testEvent     
  
  
  /** Tests the PricingSchema BO and DAO */
  public void testPricingSchema() throws Exception {
    VenueProductionCategory prodcat = VenueProductionCategoryDAO.getInstance().read("8623n");
    Section section = SectionDAO.getInstance().read("A1");
    DayOfWeek dow = DayOfWeekDAO.getInstance().read("d2");
    TimePeriod timeperiod = TimePeriodDAO.getInstance().read("tp1");
    
    String guid = GUID.generate();
    PricingSchema sis = PricingSchemaDAO.getInstance().create(guid);
    sis.setProductionCategory(prodcat);
    sis.setSection(section);
    sis.setDayOfWeek(dow);
    sis.setTimePeriod(timeperiod);
    sis.setBasePrice(40.00);
    sis.save(); // will save with insert statement
    
    sis.setBasePrice(50);
    sis.save(); // this will save with the update statement
    
    // this one will come from the cache -- should be the exact same object
    PricingSchema sis2 = PricingSchemaDAO.getInstance().read(guid);
    assertSame(sis, sis2);
    
    // this one will come all the way from the DB -- should be a new object
    Cache.getInstance().clear();
    PricingSchema sis3 = PricingSchemaDAO.getInstance().read(guid);
    assertNotSame(sis, sis3);
    assertNotNull(sis3.getProductionCategory());
    assertEquals(sis.getProductionCategory().getId(), sis3.getProductionCategory().getId());
    assertNotNull(sis3.getSection());
    assertEquals(sis.getSection().getId(), sis3.getSection().getId());
    assertNotNull(sis3.getDayOfWeek());
    assertEquals(sis.getDayOfWeek().getId(), sis3.getDayOfWeek().getId());
    assertNotNull(sis3.getTimePeriod());
    assertEquals(sis.getTimePeriod().getId(), sis3.getTimePeriod().getId());
    assertEquals(sis.getBasePrice(), sis3.getBasePrice());
    assertEquals(sis.getBasePrice(), 50.00);
    
    // test the search methods in the DAO
    List<PricingSchema> all;
    all = PricingSchemaDAO.getInstance().getAll();
    assertEquals(all.size(), 21); 
    
    // this one is a big method that gets the price for the GUI.  It will be called a lot.
    PricingSchema sis4 = PricingSchemaDAO.getInstance().getPricingSchemas(prodcat, section, dow, timeperiod);
    assertEquals(sis4.getId(), sis3.getId());
  }//testPricingSchema   
  
  
    
  /** Tests the VenueSeat BO and DAO */
  public void testVenueSeat() throws Exception {
    Section section = SectionDAO.getInstance().read("A1");
    Venue venue = VenueDAO.getInstance().read("ts03");
    
    String guid = GUID.generate();
    VenueSeat vcseat = VenueSeatDAO.getInstance().create(guid);
    vcseat.setSeatNumber(201);
    vcseat.setRowNumber(5);
    vcseat.setSection(section);
    venue.addVenueSeat(vcseat);
    vcseat.save(); // will save with insert statement
    venue.save();
    
    vcseat.setSeatNumber(250);
    vcseat.save(); // this will save with the update statement
    
    // this one will come from the cache -- should be the exact same object
    VenueSeat vcseat2 = VenueSeatDAO.getInstance().read(guid);
    assertSame(vcseat, vcseat2);
    
    // this one will come all the way from the DB -- should be a new object
    Cache.getInstance().clear();
    VenueSeat vcseat3 = VenueSeatDAO.getInstance().read(guid);
    assertNotSame(vcseat, vcseat3);
    assertEquals(vcseat.getSeatNumber(), vcseat3.getSeatNumber());
    assertEquals(vcseat.getRowNumber(), vcseat3.getRowNumber());
    assertNotNull(vcseat3.getSection());
    assertEquals(vcseat.getSection().getId(), vcseat3.getSection().getId());
    assertNotNull(vcseat3.getVenue());
    assertEquals(vcseat.getVenue().getId(), vcseat3.getVenue().getId());

    // test the search methods in the DAO
    List<VenueSeat> all;
    all = VenueSeatDAO.getInstance().getSeatsForVenue(venue);
    assertEquals(all.size(), 19); 
    
  }//testVenueConfigSeat   
  

  
  /** Tests the EventSeat BO and DAO */
  public void testEventSeat() throws Exception {
    Event event = EventDAO.getInstance().read("e001");
    VenueSeat vcseat = VenueSeatDAO.getInstance().read("vs01");
    
    String guid = GUID.generate();
    EventSeat eventseat = EventSeatDAO.getInstance().create(guid);
    event.addEventSeat(eventseat);
    eventseat.setVenueSeat(vcseat);
    eventseat.setPrice(40.00);
    eventseat.setStatus("available");
    eventseat.save(); // will save with insert statement
    event.save();
    
    eventseat.setStatus("sold");
    eventseat.save(); // this will save with the update statement
    
    // this one will come from the cache -- should be the exact same object
    EventSeat eventseat2 = EventSeatDAO.getInstance().read(guid);
    assertSame(eventseat, eventseat2);
    
    // this one will come all the way from the DB -- should be a new object
    Cache.getInstance().clear();
    EventSeat eventseat3 = EventSeatDAO.getInstance().read(guid);
    assertNotSame(eventseat, eventseat3);
    assertNotNull(eventseat3.getEvent());
    assertEquals(event.getId(), eventseat3.getEvent().getId());
    assertNotNull(eventseat3.getVenueSeat());
    assertEquals(vcseat.getId(), eventseat3.getVenueSeat().getId());
    assertEquals(eventseat.getPrice(), eventseat3.getPrice());
    assertEquals(eventseat.getStatus(), eventseat3.getStatus());
    assertEquals(eventseat3.getStatus(), "sold");

    // test the search methods in the DAO
    List<EventSeat> all;
    all = EventSeatDAO.getInstance().getEventSeats(event);
    assertEquals(event.getEventSeats().size(), all.size());
    assertEquals(all.size(), 16); 
    
  }//testEventSeat   
  
  
  /** Tests the PackageAvailableSeatConceptualPackage BO and DAO */
  public void testPackageAvailableSeatConceptualPackage() throws Exception {
    ConceptualPackage pkg = ConceptualPackageDAO.getInstance().read("cp86");
    VenueSeat seat = VenueSeatDAO.getInstance().read("vs01");
    
    String guid = GUID.generate();
    PackageAvailableSeatConceptualPackage pes = PackageAvailableSeatConceptualPackageDAO.getInstance().create(guid);
    pes.setSeat(seat);
    pes.setPackage(pkg);
    pes.save(); // will save with insert statement
    
    pes.setSeat(seat); // will make it dirty again
    pes.save(); // this will save with the update statement
    
    // this one will come from the cache -- should be the exact same object
    PackageAvailableSeatConceptualPackage pes2 = PackageAvailableSeatConceptualPackageDAO.getInstance().read(guid);
    assertSame(pes, pes2);
    
    // this one will come all the way from the DB -- should be a new object
    Cache.getInstance().clear();
    PackageAvailableSeatConceptualPackage pes3 = PackageAvailableSeatConceptualPackageDAO.getInstance().read(guid);
    assertNotSame(pes, pes3);
    assertNotNull(pes3.getSeat());
    assertEquals(pes.getSeat().getId(), pes3.getSeat().getId());
    assertNotNull(pes3.getPackage());
    assertEquals(pes.getPackage().getId(), pes3.getPackage().getId());
    
    // test the search methods in the DAO
    List<PackageAvailableSeatConceptualPackage> all;
    all = PackageAvailableSeatConceptualPackageDAO.getInstance().getByConceptualPackage(pkg);
    assertEquals(all.size(), 2); 
  }//testEventSeat 
  
  
  
  /** Tests the SectionInVenue BO and DAO */
  public void testSectionInVenue() throws Exception {
    Section section = SectionDAO.getInstance().read("A3");
    Venue venue = VenueDAO.getInstance().read("ts02");
    
    String guid = GUID.generate();
    SectionInVenue siv = SectionInVenueDAO.getInstance().create(guid);
    siv.setLocation("Location1");
    siv.setSection(section);
    siv.setVenue(venue);
    siv.save(); // will save with insert statement
    
    siv.setLocation("Location2"); // will make it dirty again
    siv.save(); // this will save with the update statement
    
    // this one will come from the cache -- should be the exact same object
    SectionInVenue siv2 = SectionInVenueDAO.getInstance().read(guid);
    assertSame(siv, siv2);
    
    // this one will come all the way from the DB -- should be a new object
    Cache.getInstance().clear();
    SectionInVenue siv3 = SectionInVenueDAO.getInstance().read(guid);
    assertNotSame(siv, siv3);
    assertNotNull(siv3.getLocation());
    assertEquals(siv.getLocation(), siv3.getLocation());
    assertNotNull(siv3.getVenue());
    assertEquals(siv.getVenue().getId(), siv3.getVenue().getId());
    assertNotNull(siv3.getSection());
    assertEquals(siv.getSection().getId(), siv3.getSection().getId());
    
    // test the search methods in the DAO
    List<SectionInVenue> all;
    all = SectionInVenueDAO.getInstance().getByVenue(venue);
    assertEquals(all.size(), 7); 
    SectionInVenue siv4 = SectionInVenueDAO.getInstance().getByVenueAndSection(venue, section);
    assertNotNull(siv4);
    assertEquals(siv.getId(), siv4.getId());
  }//testEventSeat 
  
  
  /** Tests the TicketSellerOwesVenue BO and DAO */
  public void testTicketSellerOwesVenue() throws Exception {
    TicketSeller ts = TicketSellerDAO.getInstance().read("ts01");
    Venue venue = VenueDAO.getInstance().read("ts02");
    
    String guid = GUID.generate();
    TicketSellerOwesVenue tsov = TicketSellerOwesVenueDAO.getInstance().create(guid);
    tsov.setVenue(venue);
    tsov.setTicketSeller(ts);
    tsov.setAmountOwed(500.00);
    tsov.save(); // will save with insert statement
    
    tsov.setAmountOwed(1000.00); // will make it dirty again
    tsov.save(); // this will save with the update statement
    
    // this one will come from the cache -- should be the exact same object
    TicketSellerOwesVenue tsov2 = TicketSellerOwesVenueDAO.getInstance().read(guid);
    assertSame(tsov, tsov2);
    
    // this one will come all the way from the DB -- should be a new object
    Cache.getInstance().clear();
    TicketSellerOwesVenue tsov3 = TicketSellerOwesVenueDAO.getInstance().read(guid);
    assertNotSame(tsov, tsov3);
    assertNotNull(tsov3.getVenue());
    assertEquals(tsov.getVenue().getId(), tsov3.getVenue().getId());
    assertNotNull(tsov3.getTicketSeller());
    assertEquals(tsov.getTicketSeller().getId(), tsov3.getTicketSeller().getId());
    
    // test the search methods in the DAO
    List<TicketSellerOwesVenue> all;
    all = TicketSellerOwesVenueDAO.getInstance().getByVenue(venue);
    assertEquals(all.size(), 3); 
    all = TicketSellerOwesVenueDAO.getInstance().getByTicketSeller(ts);
    assertEquals(all.size(), 3); 
  }
  
  
    
  
}//class TestCustomer